<template>
  <div id="recruitUnit">
    <el-drawer
      :visible.sync="drawer"
      direction="ltr"
      size="300"
      :with-header="false"
      >
      <el-switch
        v-model="treeType"
        active-text="同批次切换单位"
        inactive-text="同单位切换批次"
        @change="changeType"
        style="margin:20px 80px"
      />
      <el-tree
        @current-change="testf"
        ref="tree"
        node-key="id"
        :expand-on-click-node="false"
        default-expand-all
        :data="treedata"
      />
    </el-drawer>
    <!-- <el-button type="primary" size="mini" @click="drawer=true" style="float:right;margin:2px 0" icon="el-icon-s-unfold">切换年度/单位</el-button>
    <el-breadcrumb separator-class="el-icon-arrow-right" style="font-size:16px;padding-bottom:0"> -->
    <el-breadcrumb separator-class="el-icon-arrow-right" style="font-size:16px">
      <el-breadcrumb-item :to="{ path: '/' }">系统首页</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/recruit/unit/projectList' }">公开招聘</el-breadcrumb-item>
      <el-breadcrumb-item :to="{name: `recruitUnitAudit`, query: {theYear: theYear}}">{{theYear}}年度预审</el-breadcrumb-item>
      <el-breadcrumb-item >{{unitName}}</el-breadcrumb-item>
    </el-breadcrumb>
    <el-tabs v-model="activeName" type="border-card" @tab-click="tabClick" style="margin:0 0 0 10px" id="recruitUnitTabs">
      <el-tab-pane name="jihua">
        <span slot="label">
          计划申报
          <i v-if="planDeclare.state===0" class="custom icon_c_1" />
          <i v-else-if="planDeclare.state===1" class="custom icon_c_2" />
          <i v-else-if="planDeclare.state===5" class="custom icon_c_3" />
        </span>
        <jihua v-show="planDeclare.state===1" :unitId="unitId" :timestamp="timestamp1" :userType="3" :theYear="theYear" @getDetails="getDetails" :unitBeijing="unitBeijing"></jihua>
        <div v-show="planDeclare.state!==1">暂无数据</div>
      </el-tab-pane>
      <el-tab-pane name="xiada">
        <span slot="label">
          计划下达
          <i v-if="planRelease.state===0" class="custom icon_c_0" />
          <i v-else-if="planRelease.state===1" class="custom icon_c_2" />
        </span>
        <xiada :unitId="unitId" :timestamp="timestamp2" :userType="3" :theYear="theYear" @getDetails="getDetails" :unitBeijing="unitBeijing"></xiada>
      </el-tab-pane>
      <el-tab-pane name="duijie" v-if="unitBatch.batchType!=2">
        <span slot="label">
          岗位对接方案
          <i v-if="planDeclare.state!==1||planRelease.state!==1" class="custom icon_c_0" />
          <i v-else-if="postDocking.state===0" class="custom icon_c_0" />
          <i v-else-if="postDocking.state===1" class="custom icon_c_2" />
          <i v-else-if="postDocking.state===5" class="custom icon_c_3" />
        </span>
        <duijie v-if="unitBatch.jobDockingState===1" :unitId="unitId" step="bus_post_docking" :theYear="theYear" :timestamp="timestamp3" :userType="3" @getDetails="getDetails" :unitBeijing="unitBeijing"></duijie>
      </el-tab-pane>
      <el-tab-pane name="gonggao" v-if="unitBatch.announcementState!==-1">
        <span slot="label">
          招聘公告
          <i v-if="planDeclare.state!==1||planRelease.state!==1||postDocking.state!==1" class="custom icon_c_0" />
          <i v-else-if="!UnitStepStates.announcementCount1&&!UnitStepStates.announcementCount2&&!UnitStepStates.announcementCount3&&!UnitStepStates.announcementCount4" class="custom icon_c_0" />
          <i v-else-if="UnitStepStates.announcementCount1" class="custom icon_c_1" />
          <i v-else-if="UnitStepStates.announcementCount4>=UnitStepStates.postReserveCount" class="custom icon_c_2" />
          <i v-else class="custom icon_c_5" />
        </span>
        <announcement step="bus_announcement" :theYear="theYear" :timestamp="timestamp4" :userType="3" @getDetails="getDetails" :unitId="unitId"></announcement>
      </el-tab-pane>
      <el-tab-pane name="shencha">
        <span slot="label">
          审查应聘人员资格条件
          <i v-if="planDeclare.state!==1||planRelease.state!==1||postDocking.state!==1||!UnitStepStates.qualificationCount1" class="custom icon_c_0" />
          <i v-else-if="UnitStepStates.qualificationCount1<UnitStepStates.postReserveCount" class="custom icon_c_5" />
          <i v-else class="custom icon_c_2" />
        </span>
        <otherStep step="bus_qualification" :theYear="theYear" :timestamp="timestamp5" :userType="3" @getDetails="getDetails" :unitId="unitId"></otherStep>
      </el-tab-pane>
      <el-tab-pane name="kaoguan">
        <span slot="label">
          面试考官备案
          <i v-if="planDeclare.state!==1||planRelease.state!==1||postDocking.state!==1||!UnitStepStates.interviewerFilingCount1" class="custom icon_c_0" />
          <i v-else-if="UnitStepStates.interviewerFilingCount1<UnitStepStates.postReserveCount" class="custom icon_c_5" />
          <i v-else class="custom icon_c_2" />
        </span>
        <otherStep step="bus_interviewer_filing" :theYear="theYear" :timestamp="timestamp6" :userType="3" @getDetails="getDetails" :unitId="unitId"></otherStep>
      </el-tab-pane>
      <el-tab-pane name="chengji" v-if="unitBatch.batchType!=2&&unitBatch.interviewResultsState!==-1">
        <span slot="label">
          面试成绩上传
          <i v-if="planDeclare.state!==1||planRelease.state!==1||postDocking.state!==1||!UnitStepStates.interviewerResultsCount1" class="custom icon_c_0" />
          <i v-else-if="UnitStepStates.interviewerResultsCount1<UnitStepStates.postReserveCount" class="custom icon_c_5" />
          <i v-else class="custom icon_c_2" />
        </span>
        <otherStep step="bus_interviewer_results" :theYear="theYear" :timestamp="timestamp7" :userType="3" @getDetails="getDetails" :unitId="unitId"></otherStep>
      </el-tab-pane>
      <el-tab-pane name="kaocha">
        <span slot="label">
          考察
          <i v-if="planDeclare.state!==1||planRelease.state!==1||postDocking.state!==1||!UnitStepStates.investigateCount1" class="custom icon_c_0" />
          <i v-else-if="UnitStepStates.investigateCount1<UnitStepStates.postReserveCount" class="custom icon_c_5" />
          <i v-else class="custom icon_c_2" />
        </span>
        <otherStep step="bus_investigate" :theYear="theYear" :timestamp="timestamp8" :userType="3" @getDetails="getDetails" :unitId="unitId"></otherStep>
      </el-tab-pane>
      <el-tab-pane name="tijian">
        <span slot="label">
          体检
          <i v-if="planDeclare.state!==1||planRelease.state!==1||postDocking.state!==1||!UnitStepStates.physicalExaminationCount1" class="custom icon_c_0" />
          <i v-else-if="UnitStepStates.physicalExaminationCount1<UnitStepStates.postReserveCount" class="custom icon_c_5" />
          <i v-else class="custom icon_c_2" />
        </span>
        <otherStep step="bus_physical_examination" :theYear="theYear" :timestamp="timestamp9" :userType="3" @getDetails="getDetails" :unitId="unitId"></otherStep>
      </el-tab-pane>
      <el-tab-pane name="beian">
        <span slot="label">
          聘用人选备案
          <i v-if="planDeclare.state!==1||planRelease.state!==1||postDocking.state!==1||!UnitStepStates.candidateRegistrationCount1" class="custom icon_c_0" />
          <i v-else-if="UnitStepStates.candidateRegistrationCount1<UnitStepStates.postReserveCount" class="custom icon_c_5" />
          <i v-else class="custom icon_c_2" />
        </span>
        <otherStep step="bus_candidate_registration" :theYear="theYear" :timestamp="timestamp10" :userType="3" @getDetails="getDetails" :unitId="unitId"></otherStep>
      </el-tab-pane>
      <el-tab-pane name="gongshi" v-if="unitBatch.candidateAnnouncementState!==-1">
        <span slot="label">
          拟聘人选公示
          <i v-if="planDeclare.state!==1||planRelease.state!==1||postDocking.state!==1" class="custom icon_c_0" />
          <i v-else-if="!UnitStepStates.candidateAnnouncementCount1&&!UnitStepStates.candidateAnnouncementCount2&&!UnitStepStates.candidateAnnouncementCount3&&!UnitStepStates.candidateAnnouncementCount4" class="custom icon_c_0" />
          <i v-else-if="UnitStepStates.candidateAnnouncementCount1" class="custom icon_c_1" />
          <i v-else-if="UnitStepStates.candidateAnnouncementCount4>=UnitStepStates.postReserveCount" class="custom icon_c_2" />
          <i v-else class="custom icon_c_5" />
        </span>
        <announcement step="bus_candidate_announcement" :theYear="theYear" :timestamp="timestamp11" :userType="3" @getDetails="getDetails" :unitId="unitId"></announcement>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import optformJieguo from '@/components/Optform_jieguo.vue'
import optform from '@/components/Optform.vue'
import FangAn from '@/components/Fangan.vue'
import ZhiXing from '@/components/Zhixing.vue'
import jihua from './Showdata/jihua.vue'
import xiada from './Showdata/xiada.vue'
import duijie from './Showdata/duijie.vue'
import announcement from './Showdata/announcement.vue'
import kaoguan from './Showdata/kaoguan.vue'
import chengji from './Showdata/chengji.vue'
import gonggao from './Showdata/gonggao.vue'
import gongshi from './Showdata/gongshi.vue'
import beian from './Showdata/beian.vue'
import luohu from './Showdata/luohu.vue'
import otherStep from './Showdata/otherStep.vue'
export default {
  components: {
    otherStep,
    optformJieguo,
    optform,
    FangAn,
    ZhiXing,
    jihua,
    xiada,
    duijie,
    announcement,
    kaoguan,
    chengji,
    gonggao,
    gongshi,
    beian,
    luohu
  },
  data () {
    return {
      unitName: '',
      UnitStepStates: {},
      planDeclare: {},
      planRelease: {},
      postDocking: {},
      unitId: null,
      unitBeijing: null,
      theYear: null,
      batchState: false,
      batchName: null,
      unitBatch: {},
      unitBatchId: null,
      treeType: true,
      treedata: [],
      drawer: false,
      pdfpage: 1,
      shenghuohui: {
        UnitName: '',
        ShenghuohuiId: '',
        ShenghuohuiName: ''
      },
      listLoading: false,
      totalnum: 0,
      startLoading: false,
      Sortkey: '',
      Isace: true,
      Steps: [],
      OperationMsg: '',
      activeName: 'jihua',
      activeNameHuihou: 'bzzgqd',
      optForm: {},
      optFormLoading: false,
      jieguooptions: [],
      optFormRules: {
        Jieguo: [
          { required: true, message: '请选择处理结果', trigger: 'blur' }
        ]
      },
      IsOperationUser: false,
      FangAnVisible: false,
      ZhixingVisible: false,
      PingguVisible: false,
      showFangan: false,
      showZhiXing: false,
      IsFinished: false,
      banzi: [],
      banzilistLoading: false,
      huiqiantimestamp: '',
      huishangtimestamp: '',
      huihoutimestamp: '',
      timestamp1: '',
      timestamp2: '',
      timestamp3: '',
      timestamp4: '',
      timestamp5: '',
      timestamp6: '',
      timestamp7: '',
      timestamp8: '',
      timestamp9: '',
      timestamp10: '',
      timestamp11: '',
      timestamp12: '',
      timestamp13: '',
      shenghuohuinameshow: true,
      fileList: [],
      pingjiatimestamp: '',
      basesrc: '',
      lctVisible: false,
      caozuoVisible: false,
      fangantimestamp: '',
      caozuotimestamp: '',
      Operation: '',
      HaveHuiYiData: false,
      allunit: [
      ],
      allBatch: [
      ]
    }
  },
  methods: {
    getUnitName () {
      this.$http
        .get(this.$http.defaults.recruitAPI + `api/recruitBusUnit/getCurrentUnitName?unitId=` + this.unitId)
        .then(response => {
          this.unitName = response.data.result
        })
        .catch(error => {
          this.$message({
            message: '获取失败:' + error,
            type: 'error'
          })
        })
    },
    getUnitBeijing () {
      this.$http
        .get(this.$http.defaults.recruitAPI + `api/recruitBusUnit/getUnitBeijing?unitId=` + this.unitId)
        .then(response => {
          this.unitBeijing = response.data.result
        })
        .catch(error => {
          this.$message({
            message: '获取失败:' + error,
            type: 'error'
          })
        })
    },
    ftypename (type) {
      switch (type) {
        case 1:
          return '应届毕业生招聘'
        case 2:
          return '在职人员招聘'
        case 3:
          return '其他招聘'
      }
    },
    factiveName (step) {
      switch (step) {
        case 1:
          return 'jihua'
        case 2:
          return 'xiada'
        case 3:
          return 'duijie'
        case 4:
          return 'gonggao'
        case 5:
          return 'shencha'
        case 6:
          return 'kaoguan'
        case 7:
          return 'chengji'
        case 8:
          return 'kaocha'
        case 9:
          return 'tijian'
        case 10:
          return 'beian'
        case 11:
          return 'gongshi'
        case 12:
          return 'hetong'
        case 13:
          return 'luohu'
      }
    },
    fStepId (stepName) {
      switch (stepName) {
        case 'jihua':
          return 1
        case 'xiada':
          return 2
        case 'duijie':
          return 3
        case 'gonggao':
          return 4
        case 'shencha':
          return 5
        case 'kaoguan':
          return 6
        case 'chengji':
          return 7
        case 'kaocha':
          return 8
        case 'tijian':
          return 9
        case 'beian':
          return 10
        case 'gongshi':
          return 11
        case 'hetong':
          return 12
        case 'luohu':
          return 13
      }
    },
    tabClick () {
      switch (this.activeName) {
        case 'jihua':
          this.timestamp1 = new Date().getTime()
          if (this.unitBatch.planDeclareNew && this.unitBatch.planDeclareState === 1) {
            this.updateNew('planDeclare')
          }
          break
        case 'xiada':
          this.timestamp2 = new Date().getTime()
          break
        case 'duijie':
          this.timestamp3 = new Date().getTime()
          if (this.unitBatch.jobDockingNew && this.unitBatch.jobDockingState === 1) {
            this.updateNew('jobDocking')
          }
          break
        case 'gonggao':
          this.timestamp4 = new Date().getTime()
          if (this.unitBatch.announcementNew && this.unitBatch.announcementState === 1) {
            this.updateNew('announcement')
          }
          break
        case 'shencha':
          this.timestamp5 = new Date().getTime()
          if (this.unitBatch.announcementNew && this.unitBatch.announcementState === 1) {
            this.updateNew('announcement')
          }
          break
        case 'kaoguan':
          this.timestamp6 = new Date().getTime()
          if (this.unitBatch.interviewerFilingNew && this.unitBatch.interviewerFilingState === 1) {
            this.updateNew('interviewerFiling')
          }
          break
        case 'chengji':
          this.timestamp7 = new Date().getTime()
          if (this.unitBatch.interviewResultsNew && this.unitBatch.interviewResultsState === 1) {
            this.updateNew('interviewResults')
          }
          break
        case 'kaocha':
          this.timestamp8 = new Date().getTime()
          if (this.unitBatch.interviewResultsNew && this.unitBatch.interviewResultsState === 1) {
            this.updateNew('interviewResults')
          }
          break
        case 'tijian':
          this.timestamp9 = new Date().getTime()
          if (this.unitBatch.interviewResultsNew && this.unitBatch.interviewResultsState === 1) {
            this.updateNew('interviewResults')
          }
          break
        case 'beian':
          this.timestamp10 = new Date().getTime()
          if (this.unitBatch.candidateRegistrationNew && this.unitBatch.candidateRegistrationState === 1) {
            this.updateNew('candidateRegistration')
          }
          break
        case 'gongshi':
          this.timestamp11 = new Date().getTime()
          if (this.unitBatch.candidateAnnouncementNew && this.unitBatch.candidateAnnouncementState === 1) {
            this.updateNew('candidateAnnouncement')
          }
          break
        case 'hetong':
          this.timestamp12 = new Date().getTime()
          if (this.unitBatch.settlementRegistrationNew && this.unitBatch.settlementRegistrationState === 1) {
            this.updateNew('settlementRegistration')
          }
          break
        case 'luohu':
          this.timestamp13 = new Date().getTime()
          if (this.unitBatch.settlementRegistrationNew && this.unitBatch.settlementRegistrationState === 1) {
            this.updateNew('settlementRegistration')
          }
          break
      }
    },
    updateNew (step) {
      let para = {
        id: this.unitBatchId
      }
      switch (step) {
        case 'planDeclare':
          para.planDeclareNew = 0
          break
        case 'planRelease':
          para.planReleaseNew = 0
          break
        case 'jobDocking':
          para.jobDockingNew = 0
          break
        case 'interviewerFiling':
          para.interviewerFilingNew = 0
          break
        case 'interviewResults':
          para.interviewResultsNew = 0
          break
        case 'candidateRegistration':
          para.candidateRegistrationNew = 0
          break
        case 'settlementRegistration':
          para.settlementRegistrationNew = 0
          break
        case 'candidateAnnouncement':
          para.candidateAnnouncementNew = 0
          break
        case 'announcement':
          para.announcementNew = 0
          break
      }
      this.$http.post(this.$http.defaults.recruitAPI + `api/recruitBusUnitBatch/save`, para).then(response => {
        console.log(response.data.success)
        if (response.data.success !== true) {
          console.log('操作失败:' + response.data.message)
          this.$message({
            message: '操作失败:' + response.data.message,
            type: 'error'
          })
        }
      }).catch(error => {
        console.log(error)
        this.$message({
          message: '操作失败:' + error,
          type: 'error'
        })
      })
    },
    getDetails () {
      this.$http
        .get(this.$http.defaults.recruitAPI + 'api/recruitBusUnit/getUnitStepStates?theYear=' + this.theYear + '&unitId=' + this.unitId)
        .then(response => {
          if (response.data.success === true) {
            this.UnitStepStates = response.data.result
            this.planDeclare = response.data.result.plan_declare ? response.data.result.plan_declare : {state: 0}
            this.planRelease = response.data.result.plan_release ? response.data.result.plan_release : {state: 0}
            this.postDocking = response.data.result.post_docking ? response.data.result.post_docking : {state: 0}
            this.timestamp1 = new Date().getTime()
            this.timestamp2 = new Date().getTime()
            this.timestamp3 = new Date().getTime()
            this.timestamp4 = new Date().getTime()
            this.timestamp5 = new Date().getTime()
            this.timestamp6 = new Date().getTime()
            this.timestamp7 = new Date().getTime()
            this.timestamp8 = new Date().getTime()
            this.timestamp9 = new Date().getTime()
            this.timestamp10 = new Date().getTime()
            this.timestamp11 = new Date().getTime()
            this.timestamp12 = new Date().getTime()
            this.timestamp13 = new Date().getTime()
          } else {
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          console.log(error)
          this.$message({
            message: '获取失败:' + error,
            type: 'error'
          })
        })
      // this.getAllUnit()
      // this.getAllBatch()
      // this.tabClick()
    },
    changeType () {
      if (this.treeType) {
        this.treedata = this.allunit
      } else {
        this.treedata = this.allBatch
      }
    },
    getAllUnit () {
      this.$http
        .post(this.$http.defaults.recruitAPI + `api/recruitBusUnitBatch/getUnitTreeByBatchId?batchId=` + this.unitBatch.batchId)
        .then(response => {
          if (response.data.success === true) {
            this.allunit = [
              {
                id: 0,
                label: this.batchName,
                children: response.data.result
              }
            ]
            this.changeType()
          } else {
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          console.log(error)
          this.$message({
            message: '获取失败:' + error,
            type: 'error'
          })
        })
    },
    getAllBatch () {
      let para = {loginName: this.unitBatch.loginName}
      this.$http
        .post(this.$http.defaults.recruitAPI + `api/recruitBusBatch/queryByLoginName`, para)
        .then(response => {
          if (response.data.success === true) {
            this.allBatch = [
              {
                id: 0,
                label: this.unitBatch.unitName,
                children: response.data.result.map(item => {
                  return {id: item.unitBatchId, label: item.title}
                })
              }
            ]
            this.treedata = this.allBatch
            this.changeType()
          } else {
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          console.log(error)
          this.$message({
            message: '获取失败:' + error,
            type: 'error'
          })
        })
      this.treedata = this.allBatch
    },
    testf () {
      if (this.$refs.tree.getCurrentNode()['id'] !== 0 && this.$refs.tree.getCurrentNode()['id'] !== 10001 && this.$refs.tree.getCurrentNode()['id'] !== 10002 && this.$refs.tree.getCurrentNode()['id'] !== 10003) {
        console.log(this.$refs.tree.getCurrentNode()['id'])
        this.$router.push({name: 'recruitUnit', query: {step: this.fStepId(this.activeName), unitBatchId: this.$refs.tree.getCurrentNode()['id']}})

        this.activeName = this.factiveName(this.$route.query.step)
        this.unitBatchId = this.$route.query.unitBatchId
        this.getDetails()
        this.drawer = false
      }
    }
  },
  mounted () {
    this.unitId = this.$route.query.unitId
    this.theYear = this.$route.query.theYear
    this.unitBatch.planDeclareState = 1
    this.unitBatch.planReleaseState = 0
    this.unitBatch.jobDockingState = 1

    this.activeName = this.factiveName(this.$route.query.step)
    this.getUnitName()
    this.getUnitBeijing()
    this.getDetails()
  }
}
</script>
<style scoped>
#recruitlist{
  padding: 0
}
</style>
<style>
/* #recruitUnitTabs .el-tabs__item.is-active{
    color: #fff !important;
    background: #0058AC;
} */
  #recruitUnit #recruitUnitTabs i.custom{
    width: 16px;
    height: 16px;
    background-position: center center;
    background-repeat: no-repeat;
    display:inline-block;
    background-size: cover;
    margin:0 auto;
  }
  #recruitUnit .icon_c_0{
    background-image: url(../assets/icon_selection_index0.png)
  }
  #recruitUnit .icon_c_1{
    background-image: url(../assets/icon_selection_index2.gif)
  }
  #recruitUnit .icon_c_2{
    background-image: url(../assets/icon_selection_index1.png)
  }
  #recruitUnit .icon_c_-1{
    background-image: url(../assets/icon_selection_index-1.png)
  }
  #recruitUnit .icon_c_3{
    background-image: url(../assets/icon_selection_index3.png)
  }
  #recruitUnit .icon_c_3a{
    background-image: url(../assets/icon_selection_index4t.png)
  }
  #recruitUnit .icon_c_3b{
    background-image: url(../assets/icon_selection_index3b.png)
  }
  #recruitUnit .icon_c_4{
    background-image: url(../assets/icon_selection_index4t.png)
  }
  #recruitUnit .icon_c_5{
    background-image: url(../assets/icon_selection_index4r.png)
  }
</style>
